package com.hengtian.roastwall.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hengtian.roastwall.common.page.PageUtil;
import com.hengtian.roastwall.entity.Comment;
import com.hengtian.roastwall.entity.dto.AddRoastDto;
import com.hengtian.roastwall.entity.dto.CommentDTO;
import com.hengtian.roastwall.service.MomentsService;
import com.hengtian.roastwall.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api("具体功能")
@RestController
@RequestMapping("/main")
@CrossOrigin
public class MainController {

    @Autowired
    private MomentsService momentsService;

    @ApiOperation("发布吐槽")
    @PostMapping("/addRoast")
    public ResponseResult<String> addRoast(@RequestBody AddRoastDto dto) {
        String result = momentsService.addRoast(dto);
        return new ResponseResult<String>(HttpStatus.OK.value(), result, result);
    }
    //撤回吐槽
    @ApiOperation("撤回吐槽")
    @GetMapping("/delete")
    public ResponseResult withDrawComment(@RequestParam Integer commentId) {
        momentsService.deleteComment(commentId);

        return new ResponseResult(200, "操作成功");
    }

    //查询吐槽记录
    @ApiOperation("吐槽列表")
    @PostMapping("/list")
    public ResponseResult<List<Comment>> withDrawComment(@RequestBody CommentDTO commentDTO) {
        List<Comment> commentList = momentsService.commentList(commentDTO);

        return new ResponseResult<>(200, commentList);
    }
}
